<template>
    <div class="wrap">
        <div class="right" :style="{ '--after-color': color }"></div>
        <div class="box" >
            <div class="boxRight"></div>
            <slot></slot>
        </div>
    </div>
</template>
<script>
let colors = ['#138DF0', '#00B0D5', '#00E28E', '#37289F', '#2141C9']
export default {
    // 盒子右上角有一个三角形
    name: 'BoxRight',
    props: {
        index: {
            type: Number,
            default: () => 0
        }
    },
    data() {
        return {
        }
    },
    methods: {
        hexToRgba(hexColor, alpha = 1) {
            // 使用正则表达式移除可能的前导#符号
            const hex = hexColor.replace(/^\s*#|\s*$/g, '');

            // 将16进制颜色的两个字符一起转换成一个字节（0-255）
            const r = parseInt(hex.substr(0, 2), 16);
            const g = parseInt(hex.substr(2, 2), 16);
            const b = parseInt(hex.substr(4, 2), 16);

            return `rgba(${r}, ${g}, ${b}, ${alpha})`;
        }
    },
    computed: {
        color() {
            return colors[this.index % colors.length]
        },
        backColor() {
            return this.hexToRgba(colors[this.index % colors.length], 0.2)
        },
    },
    mounted() {
    }
}
</script>
<style lang="less" scoped>
.wrap {
    position: relative;
    width: 100%;
    height: 100%;
}

.content {
    position: relative;
    z-index: 2;
}

.box {
    width: 100%;
    height: 100%;
    position: relative;
    border: solid 1px #138DF0;
    // border: 1px solid transparent;
    background: linear-gradient(to bottom, rgba(24, 54, 107, 1), rgba(8, 95, 210, 0)) !important;
    clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 0 100%);

}

.box::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 20px;
    background-image: url(~@/assets/images/screen/topHight.png);
    background-size: 100% 100%;
}

.boxRight {
    position: absolute;
    top: 0px;
    right: 0px;
    width: 10px;
    height: 10px;
    background-color: transparent;
}

.boxRight::before,
.boxRight::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
}

.boxRight::before {
    top: 0;
    right: 0;
    border-top: 20px solid #138DF0;
    border-left: 20px solid transparent;
}

.right {
    position: absolute;
    width: 4px;
    height: 4px;
    top: 0px;
    right: 0px;
    background-color: transparent;
}

.right:after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    z-index: 99;
    border-left: 16px solid transparent;
    border-right: 16px solid transparent;
    border-bottom: 16px solid transparent;
    border-right-color: var(--after-color);
}
</style>